﻿#include "redis_msg_handle.h"





REDIS_PROC_S *pstGlbRedisProc = NULL;


/* func：连接redis sever的状态回调函数，只有状态切换时才会执行;
 * u32Connect[in]：0连接断开	1连接上服务端
 * */
void MC_REDIS_ConnectCallBack(uint32_t u32Connect)
{
	if(u32Connect == 1) {
		REDIS_KeyDel(pstGlbRedisProc->pstRedisHandle, pstGlbRedisProc->s8MsgListKey);
		/*开机的时候删除不是参数的key*/

		REDIS_Bgrewriteaof(pstGlbRedisProc->pstRedisHandle);
		REDIS_ClientSetName(pstGlbRedisProc->pstRedisHandle, UI_CLILENT_NAME);
	}



	return ;
}




int MC_REDIS_MSG_Handle(REDIS_MSG_S *pstMsg)
{
	int s32Ret = -1;
	REDIS_MSG_RES_S stResMsg;

	memset(&stResMsg, 0, sizeof(stResMsg));

	//if(REDIS_MSG_Pri(pstMsg->u32Cmd) == true) {
		SLOG(DBG, "s8Head:[%s] u32Cmd:[%u] u32KeyId:[%u] s8Prefix:[%s] s8ResKey:[%s]\n", pstMsg->s8Head, pstMsg->u32Cmd, pstMsg->u32KeyId, pstMsg->s8Prefix, pstMsg->s8ResKey);
	//}


	switch(pstMsg->u32Cmd) {
		default:
			SLOG(ERR, "No cmd [%u]\n", pstMsg->u32Cmd);
			break;
	}



	if(strlen(pstMsg->s8ResKey) > 0) {
		snprintf(stResMsg.s8Head, sizeof(stResMsg.s8Head), pstMsg->s8Head);
		stResMsg.u32Cmd = pstMsg->u32Cmd;
		stResMsg.s32Res = s32Ret;
		REDIS_SendMsgRes(pstGlbRedisProc->pstRedisHandle, pstMsg->s8ResKey, &stResMsg);
	}
	return s32Ret;
}

